package cn.bluemobi.platform.controller.tools;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.controller.PlatformBaseController;
import cn.bluemobi.platform.core.dto.DatatablePage;
import cn.bluemobi.platform.entity.tools.Brochure;
import cn.bluemobi.platform.service.BrochureService;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/admin/brochure")
public class BrochureController extends PlatformBaseController {

    @Autowired
    private BrochureService brochureService;

    @RequestMapping("/toBrochurePage")
    public String toBrochurePage(Model model) {
        return "brochure/brochureList";
    }

    @RequestMapping("/findBrochures")
    @ResponseBody
    public DatatablePage findBrochures(PageCondition cond) {
        return new DatatablePage(cond, brochureService.findBrochures(cond));
    }

    @RequestMapping("/toBrochureDetailPage")
    public String toBrochureDetailPage(@RequestParam(value = "brochureId", required = false) String brochureId,
            ModelMap model) {
        if (!StringUtils.isEmpty(brochureId)) {
            Brochure brochure = brochureService.findBrochureDetail(brochureId);
            model.put("brochure", brochure);
        }
        return "brochure/brochureDetail";
    }

    @RequestMapping("/saveBrochure")
    @ResponseBody
    public MapDto saveBrochure(Brochure Brochure) {
        return brochureService.saveOrUpdate(Brochure, getUser());
    }

    @RequestMapping("/deleteBrochure")
    @ResponseBody
    public MapDto deleteById(@RequestParam("brochureId") String brochureId) {
        return brochureService.deleteBrochure(brochureId, getUser());
    }

}
